<?php
/**
 * 每个站微博中关联到错误餐厅的微博
 *
 * @copyright dongping
 * @since 2012-03-24
 */


// $_GET["e_debug"] = 1;


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	
	// 分页
	cgi::both($g_cgival["p"], "p", 1);
	cgi::both($g_cgival["pcount"], "pcount", 40);
	$g_cgival["p"] = intval($g_cgival["p"]);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$g_show = $g_cgival;
	
	$p = $g_cgival["p"];
	$pcount = $g_cgival["pcount"];
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();	
	
	
	
	$db = new db_food_status();
	$db->debug = true;
	
	$data = $db->admin_get_share_with_error_res_id($site_id, $p, $pcount);
	$count = $db->admin_get_share_with_error_res_id_count($site_id);
	
		
	if (is_array($data))
	{
		$user_global_config = user_global_config::get_instance();
		
		foreach($data as $k =>$v)
		{
			
			$domain = $user_global_config->get_domain_by_site_id($v["share_site_id"]);
				
			if ($v["is_rstrt"] == 1)
			{
				$v["share_url"] = "http://{$domain}/explore/detail-{$v["status_id"]}.html";
			}
			else
			{
				$v["share_url"] = "http://{$domain}/show/detail-{$v["status_id"]}.html";
			}
							
			$data[$k] = $v;
		}
	}
	if (count($data) > 0)
	{
		$g_show["data"] = $data;
		$g_show["count"] = $count;
	}
	else
	{	
		$g_show["data_none"] = "1";
		$g_show["count"] = 0;
		
	}
	// Pager
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival['pcount'], $g_cgival["p"]);
	
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar2($page_bar_style);
	
}

try
{
	admin_check_login();
	// 	admin_check_user_priv("foodv2/main_nav.php");

	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;

	if (isset($_GET["debug"]))
	{
		echo "<pre>";
		print_r($g_show);
	}

	global $g_show;
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "foodv2/share/share_with_error_res_id.html" );
}

?>